package com.hr.lx.controller;

import com.hr.lx.annotation.Token;
import com.hr.lx.config.State;
import com.hr.lx.entity.ResponseJson;
import com.hr.lx.entity.User;
import com.hr.lx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/auth/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping(value = "/login")
    public ResponseJson login(User user) {
        if (user.getAccount() == null || user.getPwd() == null) {
            return new ResponseJson(State.FAIL, "账号和密码不能为空");
        }
        return userService.login(user.getAccount(), user.getPwd());
    }

    @Token
    @PostMapping("/get")
    public ResponseJson getMyInfo(){
        return userService.getMyInfo();
    }
}
